package com.gm.wholesale.module.webview.mainWebView;
import static com.gm.wholesale.module.main.ui.MainActivity.mActivity;
import android.webkit.JavascriptInterface;
import com.gm.commonlib.util.jsonUtils.JsonUtils;
import com.gm.commonlib.views.popupwindow.Popupwindow;
import com.gm.wholesale.module.custom.bean.CustomBean;
import com.gm.wholesale.module.good.bean.GoodBean;
import com.gm.wholesale.module.order.bean.WebViewUseBean;
import com.gm.wholesale.module.wx.bean.ShareHtmlBean;

public class MainWebViewCallBack extends Object {
    private MainWebFragment mainWebFragment;

    public MainWebViewCallBack(MainWebFragment mainWebFragment) {
        this.mainWebFragment = mainWebFragment;
    }

    // todo 登录成功后 网页回调
    @JavascriptInterface
    public void hidTitle() {
        if (mainWebFragment != null) {
            mainWebFragment.hidTitle();
        }
    }

    @JavascriptInterface
    public void viewRegularCustomer(String text) {
        CustomBean customBean = JsonUtils.parse(text, CustomBean.class);
        if (mainWebFragment != null) {
            mainWebFragment.showCustomReport(customBean);
        }

    }

    @JavascriptInterface
    public void viewRegularSku(String text) {
        GoodBean goodBean = JsonUtils.parse(text, GoodBean.class);
        if (mainWebFragment != null && goodBean != null) {
            mainWebFragment.showGoodReport(goodBean);
        }
    }

    @JavascriptInterface
    public void openOrderPayNumberKeyboard(String text) {
        if (mainWebFragment != null) {
            WebViewUseBean webViewUseBean = JsonUtils.parse(text, WebViewUseBean.class);
            mainWebFragment.showPayView(webViewUseBean);
        }

    }

    @JavascriptInterface
    public void closeOrderPayNumberKeyboard() {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Popupwindow.hiddenPop();
            }
        });
    }


    @JavascriptInterface
    public void showTitle() {
        if (mainWebFragment != null) {
            mainWebFragment.showTitle();
        }
    }

    @JavascriptInterface
    public void updateView(int type, String data) {
        if (type == 1) {
            if (mainWebFragment != null) {
              //  mainWebFragment.updateKind();
            }
        }

    }


    @JavascriptInterface
    public void updateCustom(int type, String data) {
        CustomBean customBean = JsonUtils.parse(data, CustomBean.class);
        if (mainWebFragment!=null){
            mainWebFragment.updateCustom(type, customBean);
        }

    }


    //邀请客户 填写订单需求
    @JavascriptInterface
    public void shareWx(String data) {
        ShareHtmlBean shareHtmlBean = JsonUtils.parse(data, ShareHtmlBean.class);
        if (shareHtmlBean!=null && mainWebFragment!=null){
            shareHtmlBean.setTitle("邀请您下单");
            mainWebFragment.shareWx(shareHtmlBean);
        }

    }


}
